/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.situ.studentmanagement;

import com.situ.studentmanagement.dao.StudentMapper;
import com.situ.studentmanagement.model.Student;

import javax.servlet.http.HttpSession;

/**
 *
 * @author niugao
 */
public class Constants {
    public static final String STUDENT_LOGIN_ATTR_ID="student_id";
    public static final String STUDENT_LOGIN_ATTR_NAME="student_name";
    public static final String ADMIN_LOGIN_ATTR_ID="admin_id";
    public static final int CLASS_BEGIN_TIME = 8*3600+1800;//上班时间,8:30
    public static final int CLASS_OVER_TIME = 17*3600+1800;//5:30 下班
    public static final int ABSENCE_TIME = 10*3600+1800;//10点半不到算旷工

    //取得非登录状态时，top bar右边的一段html代码
    public static String getUnloginAccountHtml(){
        return "<img src='/img/unlogin_head.png'>未登录</a>";
    }

    public static String getStudentLoginAcccountHtml(
            StudentMapper studentMapper,
            HttpSession session){
        //从数据库中获取头像的路径
        Student student = studentMapper.getStudentById((int)session.getAttribute(Constants.STUDENT_LOGIN_ATTR_ID));
        //获取帐户名
        String name= (String) session.getAttribute(Constants.STUDENT_LOGIN_ATTR_NAME);
        String img_file="avatar/default_head_img.png";
        if(student.getHeadImg()!=null)
            img_file=student.getHeadImg();

        return "<img src='/img/"+img_file+"'><a href='/student/myInfo'>"+name+"</a>";
    }

    public static String getAdminLoginAcccountHtml(){
        //TODO:未完成
        return "<img src='/img/unlogin_head.png'>未登录</a>";
    }
}
